package main

import (
	"Gin_dome/controllers"
	"Gin_dome/models"
	"Gin_dome/uitls"
	"github.com/gin-gonic/gin"
	_ "github.com/go-sql-driver/mysql"
	"html/template"
)

func main() {
	db := models.ConnectMysql()

	defer db.Close()
	//将debug 环境设置为线上环境
	gin.SetMode(gin.ReleaseMode)
	app := gin.Default()

	//自定义404处理函数
	app.NoRoute(controllers.NoResponse)
	//添加自定义的模板函数
	app.SetFuncMap(template.FuncMap{"stringadd": uitls.StringAdd,
		"timecut":    uitls.TimeCut,
		"safe":       uitls.Safe,
		"truestring": uitls.TrueString,
		"urladd":     uitls.UrlAdd,
	})
	//注册html目录
	app.LoadHTMLGlob("templates/*")
	//app.StaticFS(path + "\\static", http.Dir(path + "\\static\\"))
	//注册静态资源目录
	app.Static("static", "./static")

	//处理方法
	app.GET("/blog/", controllers.Index)

	//app.GET("/blog/:name/", controllers.Index)
	app.GET("/blog/details/:artid/", controllers.Details)
	app.GET("/blog/python/", controllers.Python)
	app.GET("/blog/golang/", controllers.Golang)
	app.GET("/blog/c++/", controllers.C)
	app.GET("/blog/database/", controllers.Database)
	app.GET("/blog/data_alg/", controllers.DataSal)
	app.GET("/blog/rests/", controllers.Rests)
	//

	app.Run(":8520")

}
